package inf3791.calendarsystem.soc;

import java.util.Date;

/**
 * Describes the time difference between two dates with the resolution of
 * minutes.
 *
 * @author Jonas Weber
 */
class TimeDifference {

    public int hour;
    public int minute;

    /**
     * calculates the difference between the two given dates.
     *
     * The first date _has_ to be later, otherwise the calculation does not work
     * correctly. Null is not supported as well for both parameters.
     */
    static TimeDifference fromSubtraction(Date a, Date b) {
        TimeDifference diff = new TimeDifference();
        long difference = a.getTime() - b.getTime();
        difference /= 1000; // convert to seconds
        // convert to seconds
        diff.hour = (int) difference / 3600;
        diff.minute = ((int) difference - 3600 * diff.hour) / 60;
        return diff;
    }
}
